package edu.ncst.baseweb.utils;

import edu.ncst.baseweb.dto.JwtUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;


@Component
public class GetUserinfoUtil {
    public JwtUser getUser() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        Object obj = authentication.getPrincipal();
        if (obj instanceof JwtUser) {
            return (JwtUser) obj;
        }
        return null;
    }

    public Authentication getAuthentication(){
        SecurityContext context = SecurityContextHolder.getContext();
        return context.getAuthentication();
    }
}
